import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/layout/index";
import AppMian from "@/layout/components/appMian";
import About from "@/views/About";
import Blank from "@/layout/blank";

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "/HomePage",
    hidden: true,
    children: [
      {
        path: "HomePage",
        name: "HomePage",
        component: () => import("@/views/homePage/index.vue"),
        meta: {
          title: "推荐驾驶舱",
          level: 1,
          alive: true,
          name: "HomePage",
        },
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/singleLogin",
    component: () => import("@/views/login/singleLogin"),
    hidden: true,
  },
  {
    path: "/loginOut",
    component: () => import("@/views/login/logout"),
    hidden: true,
  },
];

export const asyncRoutes = [
  {
    path: "/homePage",
    component: Layout,
    meta: {
      title: "推荐驾驶舱",
      level: 1,
      icon: require("@/assets/kmerit/menu/shouye.png"),
      iconGl: require("@/assets/kmerit/menu/shouye_gl.png"),
    },
  },
  {
    path: "/platform",
    component: Layout,
    meta: {
      title: "业务工作台",
      level: 1,
      icon: require("@/assets/kmerit/menu/fenxiao.png"),
      iconGl: require("@/assets/kmerit/menu/fenxiao_gl.png"),
    },
    children: [
      // {
      //   path: "test",
      //   name: "test",
      //   component: () => import("@/views/platform/test.vue"),
      //   meta: {
      //     title: "test",
      //     level: 1,
      //     alive: true,
      //     name: "test",
      //   },
      // },
      {
        path: "platform",
        name: "platform",
        component: () => import("@/views/platform/index.vue"),
        meta: {
          title: "工作台",
          level: 1,
          alive: true,
          name: "platform",
        },
      },
      {
        path: "reminders",
        name: "reminders",
        component: () => import("@/views/platform/reminders.vue"),
        meta: {
          title: "提醒事项",
          level: 1,
          alive: true,
          name: "reminders",
        },
      },
      {
        path: "todoList",
        name: "todoList",
        component: () => import("@/views/platform/todoList.vue"),
        meta: {
          title: "待办事项",
          level: 1,
          alive: true,
          name: "todoList",
        },
      },
      {
        path: "publicOpinionInformation",
        name: "publicOpinionInformation",
        component: () =>
          import("@/views/platform/publicOpinionInformation.vue"),
        meta: {
          title: "舆情信息",
          level: 1,
          alive: true,
          name: "publicOpinionInformation",
        },
      },
    ],
  },
  {
    path: "/customerManagement",
    component: Layout,
    meta: {
      title: "客户管理",
      level: 1,
      icon: require("@/assets/kmerit/menu/fenxiao.png"),
      iconGl: require("@/assets/kmerit/menu/fenxiao_gl.png"),
    },
    children: [
      // 发行人管理
      {
        path: "issuerManagement",
        name: "issuerManagement",
        component: Blank,
        meta: {
          title: "发行人管理",
          level: 2,
          alive: true,
          name: "issuerManagement",
        },
        children: [
          {
            path: "issuerManage",
            name: "issuerManage",
            component: () =>
              import("@/views/customerManagement/issuerManagement/index.vue"),
            meta: {
              title: "发行人管理",
              level: 3,
              alive: true,
              name: "issuerManage",
            },
          },
          {
            path: "issuerDetail",
            name: "issuerDetail",
            component: () =>
              import("@/views/customerManagement/issuerManagement/detail.vue"),
            meta: {
              title: "发行人管理详情",
              level: 3,
              alive: true,
              name: "issuerDetail",
            },
            // props: true,
            hidden: true,
          },
        ],
      },
      // 客户贡献度管理
      {
        path: "customerContributionManagement",
        name: "customerContributionManagement",
        component: Blank,
        meta: {
          title: "客户贡献度管理",
          level: 2,
          alive: true,
          name: "customerContributionManagement",
        },
        children: [
          {
            path: "evaluationSchemeManagement",
            name: "evaluationSchemeManagement",
            component: () =>
              import(
                "@/views/customerManagement/customerContributionManagement/evaluationSchemeManagement.vue"
              ),
            meta: {
              title: "客户评价方案制定",
              level: 3,
              alive: true,
              name: "evaluationSchemeManagement",
            },
          },
          {
            path: "evaluationResultManagement",
            name: "evaluationResultManagement",
            component: () =>
              import(
                "@/views/customerManagement/customerContributionManagement/evaluationResultManagement.vue"
              ),
            meta: {
              title: "客户评分结果",
              level: 3,
              alive: true,
              name: "EvaluationResultManagement",
            },
          },
          {
            path: "rankingChange",
            name: "rankingChange",
            component: () =>
              import(
                "@/views/customerManagement/customerContributionManagement/rankingChange.vue"
              ),
            meta: {
              title: "客户排名变动",
              level: 3,
              alive: true,
              name: "rankingChange",
            },
          },
        ],
      },
      {
        path: "customerLevelQuery",
        name: "customerLevelQuery",
        component: () =>
          import(
            "@/views/customerManagement/customerLevelManagement/customerLevelQuery.vue"
          ),
        meta: {
          title: "客户层级管理",
          level: 2,
          alive: true,
          name: "customerLevelQuery",
        },
      },
      {
        path: "customerManagement",
        name: "customerManagement",
        component: () =>
          import("@/views/customerManagement/customerMan/index.vue"),
        meta: {
          title: "客户管理",
          level: 2,
          alive: true,
          name: "customerManagement",
        },
      },
      {
        path: "customerView",
        name: "customerView",
        component: () =>
          import("@/views/customerManagement/customerView/index.vue"),
        meta: {
          title: "360客户视图",
          level: 2,
          alive: true,
          name: "customerView",
        },
        hidden: true,
      },
      {
        path: "customerAnalysis",
        name: "customerAnalysis",
        component: () =>
          import("@/views/customerManagement/customerAnalysis/index.vue"),
        meta: {
          title: "客户分析",
          level: 2,
          alive: true,
          name: "customerAnalysis",
        },
      },

      {
        path: "affiliationManagement",
        name: "affiliationManagement",
        component: () =>
          import("@/views/customerManagement/affiliationManagement/index.vue"),
        meta: {
          title: "归属管理",
          level: 2,
          alive: true,
          name: "affiliationManagement",
        },
      },
      {
        path: "admissionList",
        name: "admissionList",
        component: () =>
          import("@/views/customerManagement/admissionList/index.vue"),
        meta: {
          title: "准入名单管理",
          level: 2,
          alive: true,
          name: "admissionList",
        },
      },
      {
        path: "transactionMonitoring",
        name: "transactionMonitoring",
        component: () =>
          import("@/views/customerManagement/transactionMonitoring/index.vue"),
        meta: {
          title: "交易监控",
          level: 2,
          alive: true,
          name: "transactionMonitoring",
        },
      },
      {
        path: "keyMonitoringList",
        name: "keyMonitoringList",
        component: () =>
          import("@/views/customerManagement/keyMonitoringList/index.vue"),
        meta: {
          title: "重点监测名单",
          level: 2,
          alive: true,
          name: "keyMonitoringList",
        },
      },
      // 债券风险画像
      {
        path: "bondRiskProfile",
        name: "bondRiskProfile",
        component: () =>
          import("@/views/customerManagement/bondRiskProfile/index.vue"),
        meta: {
          title: "债券风险画像",
          level: 2,
          alive: true,
          name: "bondRiskProfile",
        },
      },
      {
        path: "bondRiskProfileDetail",
        name: "bondRiskProfileDetail",
        component: () =>
          import("@/views/customerManagement/bondRiskProfile/detail.vue"),
        meta: {
          title: "债券风险画像详情",
          level: 2,
          alive: true,
          name: "bondRiskProfileDetail",
        },
        // props: true,
        hidden: true,
      },
      //客户贡献度管理
      {
        path: "bondMarketingList",
        name: "bondMarketingList",
        component: Blank,
        meta: {
          title: "债券营销名单",
          level: 2,
          alive: true,
          name: "bondMarketingList",
        },
        children: [
          {
            path: "customersWithCoupons",
            name: "customersWithCoupons",
            component: () =>
              import(
                "@/views/customerManagement/bondMarketingList/customersWithCoupons.vue"
              ),
            meta: {
              title: "以券荐客-法人户",
              level: 3,
              alive: true,
              name: "customersWithCoupons",
            },
          },
          {
            path: "vouchersToCustomers",
            name: "vouchersToCustomers",
            component: () =>
              import(
                "@/views/customerManagement/bondMarketingList/vouchersToCustomers.vue"
              ),
            meta: {
              title: "以客荐券-法人户",
              level: 3,
              alive: true,
              name: "vouchersToCustomers",
            },
          },
        ],
      },
    ],
  },
  {
    path: "/visitManagement",
    component: Layout,
    meta: {
      title: "走访管理",
      level: 1,
      icon: require("@/assets/kmerit/menu/fenxiao.png"),
      iconGl: require("@/assets/kmerit/menu/fenxiao_gl.png"),
    },
    children: [
      {
        path: "customerDistributionMap",
        name: "customerDistributionMap",
        component: () =>
          import("@/views/visitManagement/customerDistributionMap.vue"),
        meta: {
          title: "客户分布图",
          level: 1,
          alive: true,
          name: "customerDistributionMap",
        },
      },
      {
        path: "customerVisits",
        name: "customerVisits",
        component: () => import("@/views/visitManagement/customerVisits.vue"),
        meta: {
          title: "客户来访",
          level: 1,
          alive: true,
          name: "customerVisits",
        },
      },
      {
        path: "customerVisit",
        name: "customerVisit",
        component: () => import("@/views/visitManagement/customerVisit.vue"),
        meta: {
          title: "客户拜访",
          level: 1,
          alive: true,
          name: "customerVisit",
        },
      },
    ],
  },
  {
    path: "/productManagement",
    component: Layout,
    meta: {
      title: "产品管理",
      level: 1,
      icon: require("@/assets/kmerit/menu/fenxiao.png"),
      iconGl: require("@/assets/kmerit/menu/fenxiao_gl.png"),
    },
    children: [
      {
        path: "businessCategoryManagement",
        name: "businessCategoryManagement",
        component: () =>
          import("@/views/productManagement/businessCategoryManagement.vue"),
        meta: {
          title: "业务品种管理",
          level: 2,
          alive: true,
          name: "businessCategoryManagement",
        },
      },
      {
        path: "transactionDataManagement",
        name: "transactionDataManagement",
        component: () =>
          import("@/views/productManagement/transactionDataManagement.vue"),
        meta: {
          title: "交易数据管理",
          level: 2,
          alive: true,
          name: "transactionDataManagement",
        },
      },
      {
        path: "productAnalysis",
        name: "productAnalysis",
        component: Blank,
        meta: {
          title: "产品分析",
          level: 2,
          alive: true,
          name: "productAnalysis",
        },
        children: [
          {
            path: "productTimingAnalysis",
            name: "productTimingAnalysis",
            component: () =>
              import("@/views/productManagement/productTimingAnalysis.vue"),
            meta: {
              title: "产品时序分析",
              level: 3,
              alive: true,
              name: "productTimingAnalysis",
            },
          },
        ],
      },
    ],
  },
  {
    path: "/staff",
    component: Layout,
    meta: {
      title: "员工管理",
      level: 1,
      icon: require("@/assets/kmerit/menu/fenxiao.png"),
      iconGl: require("@/assets/kmerit/menu/fenxiao_gl.png"),
    },
    children: [
      {
        path: "assessmentTask",
        name: "assessmentTask",
        component: () => import("@/views/staff/assessmentTask.vue"),
        meta: {
          title: "考核任务制定分配",
          level: 1,
          alive: true,
          name: "assessmentTask",
        },
      },
      {
        path: "distributionOfPerformance",
        name: "distributionOfPerformance",
        component: () => import("@/views/staff/distributionOfPerformance.vue"),
        meta: {
          title: "业绩分配",
          level: 1,
          alive: true,
          name: "distributionOfPerformance",
        },
      },
      {
        path: "assessmentResult",
        name: "assessmentResult",
        component: () => import("@/views/staff/assessmentResult.vue"),
        meta: {
          title: "员工考核结果",
          level: 1,
          alive: true,
          name: "assessmentResult",
        },
      },
      {
        path: "employeeAnalysis",
        name: "employeeAnalysis",
        component: () => import("@/views/staff/employeeAnalysis.vue"),
        meta: {
          title: "员工分析",
          level: 1,
          alive: true,
          name: "employeeAnalysis",
        },
      },
    ],
  },
  {
    path: "/eigenSystem",
    component: Layout,
    meta: {
      title: "特征系统",
      level: 1,
      icon: require("@/assets/kmerit/menu/baoxiao.png"),
      iconGl: require("@/assets/kmerit/menu/baoxiao_bj.png"),
    },
    children: [
      {
        path: "groupManagement",
        name: "groupManagement",
        component: () => import("@/views/eigenSystem/groupManagement"),
        meta: {
          title: "分群管理",
          // level: 2,
          alive: true,
          name: "groupManagement",
          // isLast: true,
        },
      },
      {
        path: "groupStatistics",
        name: "groupStatistics",
        component: () => import("@/views/eigenSystem/groupStatistics"),
        meta: {
          title: "对象分群统计",
          // level: 2,
          alive: true,
          name: "groupStatistics",
          // isLast: true,
        },
      },
      {
        path: "customer",
        name: "customer",
        component: () => import("@/views/eigenSystem/label/customer"),
        meta: {
          title: "客户查询",
          // level: 2,
          alive: true,
          name: "label",
          // isLast: true,
        },
      },

      {
        path: "objectQueryManagement",
        name: "objectQueryManagement",
        component: () => import("@/views/eigenSystem/objectQueryManagement"),
        meta: {
          title: "对象查询管理",
          // level: 2,
          alive: true,
          name: "objectQueryManagement",
          // isLast: true,
        },
      },

      {
        path: "customerRiskAssessment",
        name: "customerRiskAssessment",
        component: () => import("@/views/eigenSystem/customerRiskAssessment"),
        meta: {
          title: "客户风险评估",
          alive: true,
          name: "customerRiskAssessment",
          // isLast: true,
        },
      },
      {
        path: "bondRiskAppetite",
        name: "bondRiskAppetite",
        component: () =>
          import("@/views/eigenSystem/bondRiskAppetite/index.vue"),
        meta: {
          title: "债券风险偏好",
          // level: 2,
          alive: true,
          name: "bondRiskAppetite",
          // isLast: true,
        },
      },
      // {
      //   path: "persona",
      //   name: "persona",
      //   component: () => import("@/views/eigenSystem/persona"),
      //   meta: {
      //     title: "客户画像",
      //     // level: 2,
      //     alive: true,
      //     name: "persona",
      //     // isLast: true,
      //   },
      // },
      // {
      //   path: "targetManagement",
      //   name: "targetManagement",
      //   component: () =>
      //     import("@/views/featureSystem/targetManagement/index.vue"),
      //   meta: {
      //     title: "指标管理",
      //     level: 2,
      //     alive: true,
      //     name: "targetManagement",
      //   },
      // },
    ],
  },
  {
    path: "/recommendationSystem",
    component: Layout,
    meta: {
      title: "推荐系统",
      level: 1,
      icon: require("@/assets/kmerit/menu/fenxiao.png"),
      iconGl: require("@/assets/kmerit/menu/fenxiao_gl.png"),
    },
    children: [
      {
        path: "customerRisk",
        name: "customerRisk",
        component: () => import("@/views/recommendationSystem/customerRisk"),
        meta: {
          title: "客户个券风险评估",
          // level: 2,
          alive: true,
          name: "customerRisk",
        },
      },
      {
        path: "customerRecommendation",
        name: "customerRecommendation",
        component: () =>
          import("@/views/recommendationSystem/customerRecommendation"),
        meta: {
          title: "新劵荐客",
          // level: 2,
          alive: true,
          name: "customerRecommendation",
        },
      },
      {
        path: "customerTicket",
        name: "customerTicket",
        component: () => import("@/views/recommendationSystem/customerTicket"),
        meta: {
          title: "新客荐券",
          // level: 2,
          alive: true,
          name: "customerTicket",
        },
      },
      {
        path: "singleDebtCustomer",
        name: "singleDebtCustomer",
        component: () =>
          import("@/views/recommendationSystem/singleDebtCustomer"),
        meta: {
          title: "单债客群",
          // level: 2,
          alive: true,
          name: "singleDebtCustomer",
        },
      },
      {
        path: "singleCustomerDebtGroup",
        name: "singleCustomerDebtGroup",
        component: () =>
          import("@/views/recommendationSystem/singleCustomerDebtGroup"),
        meta: {
          title: "单客债群",
          // level: 2,
          alive: true,
          name: "singleCustomerDebtGroup",
        },
      },
    ],
  },
  // {
  //   path: '/opportunityLibrary',
  //   component: Layout,
  //   meta: {
  //     title: '商机库',
  //     level: 1,
  //     icon: require('@/assets/kmerit/menu/fenxiao.png'),
  //     iconGl: require('@/assets/kmerit/menu/fenxiao_gl.png'),
  //   },
  //   children: [{
  //       path: 'marketData',
  //       name: 'marketData',
  //       component: Blank,
  //       meta: {
  //         title: '市场数据',
  //         level: 2,
  //         alive: true,
  //         name: 'marketData',
  //       },
  //       children: [{
  //           path: "regionalLnnovationIndex",
  //           name: "regionalLnnovationIndex",
  //           component: () => import("@/views/opportunityLibrary/marketData/regionalLnnovationIndex.vue"),
  //           meta: {
  //             title: '区域创新指数',
  //             level: 3,
  //             alive: true,
  //             name: 'regionalLnnovationIndex',
  //           },
  //         },
  //         {
  //           path: 'RegulatoryPolicy',
  //           name: 'RegulatoryPolicy',
  //           component: () =>
  //             import(
  //               '@/views/opportunityLibrary/marketData/RegulatoryPolicy.vue'
  //             ),
  //           meta: {
  //             title: '监管政策',
  //             level: 3,
  //             alive: true,
  //             name: 'RegulatoryPolicy',
  //           },
  //         },
  //         {
  //           path: 'majorNewsEvents',
  //           name: 'majorNewsEvents',
  //           component: () =>
  //             import(
  //               '@/views/opportunityLibrary/marketData/majorNewsEvents.vue'
  //             ),
  //           meta: {
  //             title: '重大新闻事件',
  //             level: 3,
  //             alive: true,
  //             name: 'majorNewsEvents',
  //           },
  //         },
  //         {
  //           path: 'regionalEconomicData',
  //           name: 'regionalEconomicData',
  //           component: () =>
  //             import(
  //               '@/views/opportunityLibrary/marketData/regionalEconomicData.vue'
  //             ),
  //           meta: {
  //             title: '区域经济数据',
  //             level: 3,
  //             alive: true,
  //             name: 'regionalEconomicData',
  //           },
  //         },
  //       ],
  //     },
  //     {
  //       path: 'IssuerManagement',
  //       name: 'IssuerManagement',
  //       component: () => import('@/views/opportunityLibrary/IssuerManagement'),
  //       meta: {
  //         title: '发行主体管理',
  //         // level: 2,
  //         alive: true,
  //         name: 'IssuerManagement',
  //       },
  //     },
  //     {
  //       path: 'IssuerStatementDetails',
  //       name: 'IssuerStatementDetails',
  //       component: () => import('@/views/opportunityLibrary/IssuerStatementDetails'),
  //       meta: {
  //         title: '发行主体报表',
  //         // level: 2,
  //         alive: true,
  //         name: 'IssuerStatementDetails',
  //       },
  //     },
  //     {
  //       path: 'eventGraph',
  //       name: 'eventGraph',
  //       component: () => import('@/views/opportunityLibrary/eventGraph'),
  //       meta: {
  //         title: '事件图谱',
  //         // level: 2,
  //         alive: true,
  //         name: 'eventGraph',
  //       },
  //     },
  //     {
  //       path: 'knowledgeBase',
  //       name: 'knowledgeBase',
  //       component: () => import('@/views/opportunityLibrary/knowledgeBase'),
  //       meta: {
  //         title: '知识库',
  //         // level: 2,
  //         alive: true,
  //         name: 'knowledgeBase',
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '/editSystem',
  //   component: Layout,
  //   meta: {
  //     title: '分析工作台',
  //     level: 1,
  //     icon: require('@/assets/kmerit/menu/xitongguanli.png'),
  //     iconGl: require('@/assets/kmerit/menu/xitongguanli_gl.png'),
  //   },
  //   children: [{
  //       path: 'REdit',
  //       name: 'REdit',
  //       component: () => import('@/views/editSystem/rEdit/index.vue'),
  //       meta: {
  //         title: 'R语言编辑器',
  //         level: 1,
  //         alive: true,
  //         name: 'REdit',
  //       },
  //     },
  //     {
  //       path: 'PythonEdit',
  //       name: 'PythonEdit',
  //       component: () => import('@/views/editSystem/pythonEdit/index.vue'),
  //       meta: {
  //         title: 'Python语言编辑器',
  //         level: 1,
  //         alive: true,
  //         name: 'PythonEdit',
  //       },
  //     },
  //   ],
  // },
];

const createRouter = () =>
  new VueRouter({
    mode: "history", // require service support
    base: process.env.VUE_APP_FRONT_BASE_URL, // 前端路径
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
